package com.gjy.sql.regexp;

import org.junit.Test;

/**
 * @author gjy
 * @version 1.0
 * @since 2024-02-28 18:01:33
 */
public class CharTest {

    public static boolean validateString(String input) {
        if (input == null || input.isEmpty() || input.length() > 50) {
            return false;
        }

        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (!Character.isLetterOrDigit(c) && !isChinese(c)) {
                return false;
            }
        }

        return true;
    }

    private static boolean isChinese(char c) {
        return Character.UnicodeScript.of(c) == Character.UnicodeScript.HAN;
    }

    @Test
    public void test() {
        String input = "你好12@3abc";
        if (validateString(input)) {
            System.out.println("String is valid");
        } else {
            System.out.println("String is invalid");
        }
    }
}
